home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / lib / jsprintf.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-07  |  2.5 KB  |  123 lines

  1. /* @(#)jsprintf.c    1.13 00/05/07 Copyright 1985 J. Schilling */
  2. /*
  3.  *    Copyright (c) 1985 J. Schilling
  4.  */
  5. /*
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; see the file COPYING.  If not, write to
  18.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #include <mconfig.h>
  22. #include <stdio.h>
  23. #include <vadefs.h>
  24. #include <standard.h>
  25. #include <schily.h>
  26.  
  27. #define BFSIZ    256
  28.  
  29. typedef struct {
  30.     short    cnt;
  31.     char    *ptr;
  32.     char    buf[BFSIZ];
  33.     int    count;
  34.     FILE    *f;
  35. } *BUF, _BUF;
  36.  
  37. LOCAL    void    _bflush        __PR((BUF));
  38. LOCAL    void    _bput        __PR((char, long));
  39. EXPORT    int    js_fprintf    __PR((FILE *, const char *, ...));
  40. EXPORT    int    js_printf    __PR((const char *, ...));
  41.  
  42. LOCAL void _bflush (bp)
  43.     register BUF    bp;
  44. {
  45.     bp->count += bp->ptr - bp->buf;
  46.     if (filewrite (bp->f, bp->buf, bp->ptr - bp->buf) < 0)
  47.         bp->count = EOF;
  48.     bp->ptr = bp->buf;
  49.     bp->cnt = BFSIZ;
  50. }
  51.  
  52. #ifdef    PROTOTYPES
  53. LOCAL void _bput (char c, long l)
  54. #else
  55. LOCAL void _bput (c, l)
  56.         char    c;
  57.         long    l;
  58. #endif
  59.     register BUF    bp = (BUF)l;
  60.  
  61.     *bp->ptr++ = c;
  62.     if (--bp->cnt <= 0)
  63.         _bflush (bp);
  64. }
  65.  
  66. /* VARARGS2 */
  67. #ifdef    PROTOTYPES
  68. EXPORT int js_printf(const char *form, ...)
  69. #else
  70. EXPORT int js_printf(form, va_alist)
  71.     char    *form;
  72.     va_dcl
  73. #endif
  74. {
  75.     va_list    args;
  76.     _BUF    bb;
  77.  
  78.     bb.ptr = bb.buf;
  79.     bb.cnt = BFSIZ;
  80.     bb.count = 0;
  81.     bb.f = stdout;
  82. #ifdef    PROTOTYPES
  83.     va_start(args, form);
  84. #else
  85.     va_start(args);
  86. #endif
  87.     format(_bput, (long)&bb, form, args);
  88.     va_end(args);
  89.     if (bb.cnt < BFSIZ)
  90.         _bflush (&bb);
  91.     return (bb.count);
  92. }
  93.  
  94. /* VARARGS3 */
  95. #ifdef    PROTOTYPES
  96. EXPORT int js_fprintf(FILE *file, const char *form, ...)
  97. #else
  98. EXPORT int js_fprintf(file, form, va_alist)
  99.     FILE    *file;
  100.     char    *form;
  101.     va_dcl
  102. #endif
  103. {
  104.     va_list    args;
  105.     _BUF    bb;
  106.  
  107.     bb.ptr = bb.buf;
  108.     bb.cnt = BFSIZ;
  109.     bb.count = 0;
  110.     bb.f = file;
  111. #ifdef    PROTOTYPES
  112.     va_start(args, form);
  113. #else
  114.     va_start(args);
  115. #endif
  116.     format(_bput, (long)&bb, form, args);
  117.     va_end(args);
  118.     if (bb.cnt < BFSIZ)
  119.         _bflush (&bb);
  120.     return (bb.count);
  121. }
  122.